package com.ymatou.shoppingcart.api.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.shoppingcart.api.parameter.GetShoppingCartItemCountBean;
import com.ymatou.shoppingcart.api.service.GetShoppingCartItemCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.ShoppingCartCallServices;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.constant.ECode;

/**
 * 查询购物车商品规格数量 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetShoppingCartItemCount {
	private static GetShoppingCartItemCountBean countbean;
	private static GetShoppingCartItemCountCall countcall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询购物车商品规格数量");
	}

	@Before
	public void caseUp() {
		countbean = new GetShoppingCartItemCountBean();
		countcall = new GetShoppingCartItemCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(countcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetShoppingCartItemCount_001() {
		Logger.start(true,"根据UserId查询购物车商品规格数量记录成功");
		try {
			String uid = TestDataManager.getRandomUUID().toString();
			Logger.comment("动态给用户添加一条购物车记录，uid：" + uid);
			Map m = ShoppingCartCallServices.addCatalogToCart(uid);
			Logger.comment("setUserID:" + uid);
			countbean.setUserId(uid);
			countcall.setData(countbean);
			countcall.callService();
			Logger.comment("countcall send:" + countcall.getEntityString());
			Logger.comment("countcall return:" + countcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, countcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, countcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals("1", countcall.getNum(), "验证返回Num");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetShoppingCartItemCount_002() {
		Logger.start(true,"不输入必填项UserId，查询购物车商品规格数量记录失败");
		try {
			// String uid= TestDataManager.getRandomUUID().toString();
			// Logger.comment("动态给用户添加一条购物车记录，uid："+uid);
			// Map m=ShoppingCartCallServices.addCatalogToCart(uid);
			// Logger.comment("setUserID:"+uid);
			// countbean.setUserId(uid);
			countcall.setData(countbean);
			countcall.callService();
			Logger.comment("countcall send:" + countcall.getEntityString());
			Logger.comment("countcall return:" + countcall.getReturnData());
			Logger.verifyEquals(ECode.ERROR400, countcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, countcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, countcall.getMsg().contains(ECode.ERROR400_MSG_1), "验证返回Msg是否包含字符:"
					+ ECode.ERROR400_MSG_1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_GetShoppingCartItemCount_003() {
		Logger.start(true,"根据UserId查询购物车商品规格数量记录成功，添加多条");
		try {
			String uid = TestDataManager.getRandomUUID().toString();
			Logger.comment("动态给用户添加多条购物车记录，uid：" + uid);
			int n = ShoppingCartCallServices.addCatalogsToCart(uid, 10);
			Logger.comment("setUserID:" + uid);
			countbean.setUserId(uid);
			countcall.setData(countbean);
			countcall.callService();
			Logger.comment("countcall send:" + countcall.getEntityString());
			Logger.comment("countcall return:" + countcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, countcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, countcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(String.valueOf(n), countcall.getNum(), "验证返回Num");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}